package com.codegeek.project.slope.service.impl;

import com.codegeek.common.utils.DateUtils;
import com.codegeek.project.slope.domain.SlopePoint;
import com.codegeek.project.slope.mapper.SlopePointMapper;
import com.codegeek.project.slope.service.ISlopePointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 监测点位Service业务层处理
 *
 * @author codegeek
 * @date 2020-02-17
 */
@Service
public class SlopePointServiceImpl implements ISlopePointService {
    @Autowired
    private SlopePointMapper slopePointMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 查询监测点位
     *
     * @param pointId 监测点位ID
     * @return 监测点位
     */
    @Override
    public SlopePoint selectSlopePointById(Long pointId) {
        return slopePointMapper.selectSlopePointById(pointId);
    }

    /**
     * 查询监测点位列表
     *
     * @param slopePoint 监测点位
     * @return 监测点位
     */
    @Override
    public List<SlopePoint> selectSlopePointList(SlopePoint slopePoint) {
        return slopePointMapper.selectSlopePointList(slopePoint);
    }

    /**
     * 新增监测点位
     *
     * @param slopePoint 监测点位
     * @return 结果
     */
    @Override
    public int insertSlopePoint(SlopePoint slopePoint) {
        slopePoint.setCreateTime(DateUtils.getNowDate());
        return slopePointMapper.insertSlopePoint(slopePoint);
    }

    /**
     * 修改监测点位
     *
     * @param slopePoint 监测点位
     * @return 结果
     */
    @Override
    public int updateSlopePoint(SlopePoint slopePoint) {
        slopePoint.setUpdateTime(DateUtils.getNowDate());
        return slopePointMapper.updateSlopePoint(slopePoint);
    }

    /**
     * 批量删除监测点位
     *
     * @param pointIds 需要删除的监测点位ID
     * @return 结果
     */
    @Override
    public int deleteSlopePointByIds(Long[] pointIds) {
        return slopePointMapper.deleteSlopePointByIds(pointIds);
    }

    /**
     * 删除监测点位信息
     *
     * @param pointId 监测点位ID
     * @return 结果
     */
    @Override
    public int deleteSlopePointById(Long pointId) {
        return slopePointMapper.deleteSlopePointById(pointId);
    }

    /**
     * 修改状态是否禁用
     *
     * @param slopePoint
     * @return
     */
    @Override
    public Integer changeStatus(SlopePoint slopePoint) {
        return slopePointMapper.changeStatus(slopePoint);
    }

    @Override
    public List<Map<String, Object>> checkPointName(String name) {
        StringBuilder sql = new StringBuilder("select * from slope_point where point_name = '" + name + "'");
        return jdbcTemplate.queryForList(sql.toString());
    }
}
